﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Design;
using Microsoft.Windows.Design.Metadata;
using Microsoft.Windows.Design.PropertyEditing;
using AEA.WPFControls;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Windows;

namespace AEA.WPFControls.Design
{
    public class SplitButtonItemAdd : NewItemFactory
    {
        public override object CreateInstance(Type type)
        {
            SplitButtonItem splitButtonItem = null;

            if (type.IsAssignableFrom(typeof(System.Windows.Controls.ListBoxItem)))
            {
                splitButtonItem = new SplitButtonItem();
            }
            else
            {
                splitButtonItem = Activator.CreateInstance(type) as SplitButtonItem;
            }

            return splitButtonItem;
        }

        //public override object GetImage(Type type, System.Windows.Size desiredSize)
        //{
        //    object image = base.GetImage(type, desiredSize);
        //    image = Util.GetImage("SplitButtonItem.png", desiredSize);
        //    return image;
        //}
    }

    internal static class Util
    {
        private const string ResourceLocationBase = @"/AEA.WPFControls.Design;component";

        internal static Image GetImage(string imageName, Size desiredSize)
        {
            System.Uri resourceLocater = new System.Uri(ResourceLocationBase + "/Images/" + imageName, System.UriKind.RelativeOrAbsolute);
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = resourceLocater;
            bi.EndInit();

            Image image = new Image();
            image.Source = bi;
            image.Width = desiredSize.Width;
            image.Height = desiredSize.Height;
            return image;
        }
    }
}
